import http from '@/utils/request'

/**
 * 获取角色列表
 * @returns
 */
export const roleListApi = () => {
    return http('/roles', 'get')
}

/**
 * 删除角色对应的权限
 * @param {Number} roleId 角色Id
 * @param {Number} rightId 权限Id
 * @returns
 */

export const delRolePrivilegeApi = ({
    roleId,
    rightId
}) => {
    return http(`/roles/${roleId}/rights/${rightId}`, 'delete')
}

/**
 * 添加角色信息
 * @param {String} roleName 角色名称
 * @param {String} roleDesc 角色描述
 * @returns
 */

export const addRoleApi = ({
    roleName,
    roleDesc
}) => {
    return http('/roles', 'post', {
        roleName,
        roleDesc
    })
}

/**
 * 修改角色信息
 * @param {Number} id 角色id
 *  * @param {String} roleName 角色名称
 * @param {String} roleDesc 角色描述
 * @returns
 */

export const editRoleApi = ({
    id,
    roleName,
    roleDesc
}) => {
    return http(`/roles/${id}`, 'put', {
        roleName,
        roleDesc
    })
}

/**
 * 删除角色
 * @param {*Number} id 角色id
 * @returns
 */
export const delRoleApi = id => {
    return http(`/roles/${id}`, 'delete')
}

/**
 * 给角色分配权限
 * @param {Number} roleId 角色id
 * @param {String} rids 权限id列表
 * @returns
 */

export const setRoleRightsApi = (roleId, rids) => {
    return http(`/roles/${roleId}/rights`, 'post', {
        rids
    })
}